#ifndef WF_DIALOGFACTORY_H
#define WF_DIALOGFACTORY_H

#include <qwidget.h>
#include <QToolBar>

#include "pf_dialogfactoryinterface.h"
#include "pf_vector.h"
#include "pf_debug.h"
#include "gui_export.h"

/*
#include "ui_cadtoolbar.h"
#include "ui_coordinatewidget.h"
#include "ui_selectionwidget.h"
#include "ui_mousewidget.h"
#include "ui_printpreviewoptions.h"
*/

class UI_CadToolBar;
class QToolBar;
class UI_CoordinateWidget;
class UI_SelectionWidget;
class UI_MouseWidget;
//class PrintPreviewOptions;
class UI_CommandWidget;
class WF_MainWindowInterface;
class PF_Document;

#define QG_DIALOGFACTORY (PF_DialogFactory::instance()->getFactoryObject()->isAdapter()==false ? ((WF_DialogFactory*)PF_DialogFactory::instance()->getFactoryObject()) : NULL)

/**
 * This is the Qt implementation of a widget which can create and
 * show dialogs.
 */
class GUI_EXPORT WF_DialogFactory: public PF_DialogFactoryInterface {
public:
    WF_DialogFactory(QWidget* parent, QToolBar* ow);
    virtual ~WF_DialogFactory();


    /**
     * Links factory to a widget that can host tool options.
     */
    virtual void setOptionWidget(QToolBar* ow) {
		PF_DEBUG->print("QG_DialogFactory::setOptionWidget");
        optionWidget = ow;
		PF_DEBUG->print("QG_DialogFactory::setOptionWidget: OK");
    }

public:
    /**
     * Links this dialog factory to a coordinate widget.
     */
    virtual void setCoordinateWidget(UI_CoordinateWidget* cw) {
        coordinateWidget = cw;
    }

    /**
     * Links this dialog factory to a mouse widget.
     */
    virtual void setMouseWidget(UI_MouseWidget* mw) {
        mouseWidget = mw;
    }
	
    /**
     * Links this dialog factory to a selection widget.
     */
    virtual void setSelectionWidget(UI_SelectionWidget* sw) {
        selectionWidget = sw;
    }

    /**
     * Links this dialog factory to the cad tool bar.
     */
    virtual void setCadToolBar(UI_CadToolBar* ctb) {
        cadToolBar = ctb;
    }

    /**
     * @return cad tool bar or NULL.
     */
    UI_CadToolBar* getCadToolBar() {
        return cadToolBar;
    }

    /**
     * Links this dialog factory to a command widget.
     */
    virtual void setCommandWidget(UI_CommandWidget* cw) {
        commandWidget = cw;
    }

    /**
     * @return command widget or NULL.
     */
    UI_CommandWidget* getCommandWidget() {
        return commandWidget;
    }
	
    /**
     * Links the dialog factory to a main app window.
     */
    virtual void setMainWindow(WF_MainWindowInterface* mw) {
        mainWindow = mw;
    }


    virtual void requestWarningDialog(const PF_String& warning);
	
    virtual PF_GraphicView* requestNewDocument(const PF_String& fileName = PF_String::null, 
			PF_Document* doc=NULL);

    virtual PF_Layer* requestNewLayerDialog(
        PF_LayerList* layerList = NULL);
    virtual PF_Layer* requestLayerRemovalDialog(
        PF_LayerList* layerList = NULL);
    virtual PF_Layer* requestEditLayerDialog(
        PF_LayerList* layerList = NULL);

    virtual PF_BlockAttribute requestNewBlockDialog(PF_BlockList* blockList);
    virtual PF_Block* requestBlockRemovalDialog(
        PF_BlockList* blockList);
    virtual PF_BlockAttribute requestBlockAttributesDialog(
        PF_BlockList* blockList);
    virtual void requestEditBlockWindow(
        PF_BlockList* /*blockList*/) {}
    virtual void closeEditBlockWindow(
        PF_Block* /*blockList*/) {}
    //virtual PF_String requestFileSaveAsDialog();
    //virtual PF_String requestFileOpenDialog();
	
    virtual PF_String requestImageOpenDialog();


    virtual void requestOptions(PF_ActionInterface* action,
                                bool on, bool update = false);

protected:
    virtual void requestPrintPreviewOptions(PF_ActionInterface* action,
                                    bool on, bool update);
    virtual void requestLineOptions(PF_ActionInterface* action,
                                    bool on);
    virtual void requestPolylineOptions(PF_ActionInterface* action,
                                    bool on, bool update);
    virtual void requestLineAngleOptions(PF_ActionInterface* action,
                                         bool on, bool update);
    virtual void requestLineRelAngleOptions(PF_ActionInterface* action,
                                            bool on, bool update);
    virtual void requestLineParallelOptions(PF_ActionInterface* action,
                                            bool on, bool update);
    virtual void requestLineParallelThroughOptions(PF_ActionInterface* action,
                                            bool on, bool update);
    virtual void requestLineBisectorOptions(PF_ActionInterface* action,
                                            bool on, bool update);
    virtual void requestLinePolygonOptions(PF_ActionInterface* action,
                                            bool on, bool update);
    virtual void requestLinePolygon2Options(PF_ActionInterface* action,
                                            bool on, bool update);

    virtual void requestArcOptions(PF_ActionInterface* action,
                                   bool on, bool update);
    
	virtual void requestArcTangentialOptions(PF_ActionInterface* action,
                                   bool on, bool update);

    virtual void requestCircleOptions(PF_ActionInterface* action,
                                      bool on, bool update);
									  
    virtual void requestSplineOptions(PF_ActionInterface* action,
                                      bool on, bool update);
									  
    virtual void requestTextOptions(PF_ActionInterface* action,
                                   bool on, bool update);

    virtual void requestDimensionOptions(PF_ActionInterface* action,
                                         bool on, bool update);
    virtual void requestDimLinearOptions(PF_ActionInterface* action,
                                         bool on, bool update);
										 
    virtual void requestInsertOptions(PF_ActionInterface* action,
                                   bool on, bool update);
    virtual void requestImageOptions(PF_ActionInterface* action,
                                   bool on, bool update);
										 
    virtual void requestTrimAmountOptions(PF_ActionInterface* action,
                                          bool on, bool update);
    virtual void requestMoveRotateOptions(PF_ActionInterface* action,
                                          bool on, bool update);
    virtual void requestBevelOptions(PF_ActionInterface* action,
                                     bool on, bool update);
    virtual void requestRoundOptions(PF_ActionInterface* action,
                                     bool on, bool update);
    virtual void requestLibraryInsertOptions(PF_ActionInterface* action,
                                     bool on, bool update);

public:
    virtual void requestSnapDistOptions(double& dist, bool on);

public:
    virtual void requestToolBar(LX_Define::ToolBarId id);
    virtual void requestToolBarSelect(PF_ActionInterface* selectAction,
                                      LX_Define::ActionType nextAction);

    virtual bool requestAttributesDialog(PF_AttributesData& data, 
				PF_LayerList& layerList);
    virtual bool requestMoveDialog(PF_MoveAttribute& data);
    virtual bool requestRotateDialog(PF_RotateAttribute& data);
    virtual bool requestScaleDialog(PF_ScaleAttribute& data);
    virtual bool requestMirrorDialog(PF_MirrorAttribute& data);
    virtual bool requestMoveRotateDialog(PF_MoveRotateAttribute& data);
    virtual bool requestRotate2Dialog(PF_Rotate2Attribute& data);
	
    virtual bool requestModifyEntityDialog(PF_Entity* entity);
    virtual bool requestTextDialog(PF_Text* text);
    virtual bool requestHatchDialog(PF_Hatch* hatch);
	
    virtual void requestOptionsGeneralDialog();
    virtual void requestOptionsDrawingDialog(PF_Graphic& graphic);

    virtual void requestPreviousMenu();

    virtual void updateCoordinateWidget(const PF_Vector& abs,
                                        const PF_Vector& rel,
										bool updateFormat=false);
    virtual void updateMouseWidget(const PF_String& left,
                                   const PF_String& right);
    virtual void updateSelectionWidget(int num);
    virtual void commandMessage(const PF_String& message);
	virtual bool isAdapter() { return false; }

	static QString extToFormat(const QString& ext);


protected:
    //! Pointer to the widget which can host dialogs
    QWidget* parent;
    //! Pointer to the widget which can host individual tool options
    QToolBar* optionWidget;
    //! Pointer to the coordinate widget.
    UI_CoordinateWidget* coordinateWidget;
    //! Pointer to the mouse widget.
    UI_MouseWidget* mouseWidget;
    //! Pointer to the selection widget.
    UI_SelectionWidget* selectionWidget;
    //! Pointer to the CAD tool bar
    UI_CadToolBar* cadToolBar;
    //! Pointer to the command line widget
    UI_CommandWidget* commandWidget;
    //! Pointer to the main app window
    WF_MainWindowInterface* mainWindow;
};

#endif
